import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { fetchCartPostSlice, IBall, IResponse } from './cart.actions';
import { fetchUserMeSlice } from './use.actions';

interface IBalls {
  user: IBall[];
  loading: boolean;
  errors: null;
  success: boolean;
}

const initialState = {
	user: {},
	loading: false,
	errors: null,
	success: false
};

export const userMeSlice = createSlice({
	name: 'userMe',
	initialState,
	reducers: {
	},
	extraReducers: (builder) => {
		builder.addCase(fetchUserMeSlice.pending, (state) => {
			state.loading = true;
			state.errors = null;
		});
		builder.addCase(
			fetchUserMeSlice.fulfilled,
			(state, action) => {
				state.user = action.payload;
				state.loading = false;
			}
		);
		builder.addCase(fetchUserMeSlice.rejected, (state, action) => {
			// state.loading = true;
			state.errors = action.error.message;
		});
	}
});

export default userMeSlice.reducer;

